package me.khrystal.rxnews.module.video.ui;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import me.khrystal.rxnews.R;
import me.khrystal.rxnews.annotation.ActivityFragmentInject;
import me.khrystal.rxnews.base.BaseActivity;
import me.khrystal.rxnews.base.BaseFragment;
import me.khrystal.rxnews.base.BaseFragmentAdapter;
import me.khrystal.rxnews.http.Api;
import me.khrystal.rxnews.module.video.presenter.IVideoPresenter;
import me.khrystal.rxnews.module.video.presenter.IVideoPresenterImpl;
import me.khrystal.rxnews.module.video.view.IVideoView;
import me.khrystal.rxnews.utils.ViewUtil;

/**
 * usage:
 * author: kHRYSTAL
 * create time: 16/5/1
 * update time:
 * email: 723526676@qq.com
 */
@ActivityFragmentInject(
        contentViewId = R.layout.activity_video,
        hasNavigationView =  true,
        toolbarTitle = R.string.video,
        menuId = R.menu.menu_video,
        toolbarIndicator = R.drawable.ic_list_white,
        menuDefaultCheckedItem = R.id.action_video
)
public class VideoActivity extends BaseActivity<IVideoPresenter>
        implements IVideoView{

    @Override
    protected void initView() {
        mPresenter = new IVideoPresenterImpl(this);
    }

    @Override
    public void initViewPager() {
        final TabLayout tabLayout = (TabLayout)findViewById(R.id.tabs);
        ViewPager viewPager = (ViewPager)findViewById(R.id.viewpager);

        List<BaseFragment> fragments = new ArrayList<>();
        final  List<String> title = Arrays.asList("热点","娱乐","搞笑","精品");

        fragments.add(VideoListFragment.newInstance(Api.VIDEO_HOT_ID,0));
        fragments.add(VideoListFragment.newInstance(Api.VIDEO_ENTERTAINMENT_ID,1));
        fragments.add(VideoListFragment.newInstance(Api.VIDEO_FUN_ID,2));
        fragments.add(VideoListFragment.newInstance(Api.VIDEO_CHOICE_ID,3));

        BaseFragmentAdapter adapter = new BaseFragmentAdapter(getSupportFragmentManager()
                ,fragments,title);

        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        ViewUtil.dynamicSetTablayoutMode(tabLayout);
    }
}
